<?php

namespace App\Http\Controllers\Innerend;

use App\Models\SiteCate;
use App\Models\Topic;
use App\Models\User;
use Illuminate\Support\Facades\Cookie;
use Illuminate\Support\Facades\Crypt;
use App\Models\Admin;
use Illuminate\Support\Facades\Redirect;

class SearchController extends BaseController
{
    // 搜索

    // 初始化
    public function initialize()
    {
        parent::initialize();
    }

    // 搜索用户
    public function user()
    {
        $keyword = $this->getData('keyword', null, 'trim');
        $userDb  = new User();
        $where   = [['username', 'like', "%$keyword%"]];
        $lists   = $userDb->where($where)->select(['id', 'username'])->get();

        return $this->success($lists);
    }

    // 搜索新闻栏目
    public function cate()
    {
        $keyword = $this->getData('keyword', null, 'trim');
        $cateDb  = new SiteCate();
        $where   = [['title', 'like', "%$keyword%"], ['status', '=', 1]];
        $lists   = $cateDb->where($where)->select(['id', 'title'])->get();

        return $this->success($lists);
    }

    // 搜索：话筒
    public function topic()
    {
        $keyword = $this->getData('keyword', null, 'trim');
        $topicDb = new Topic();
        $where   = [['title', 'like', "%$keyword%"], ['status', '=', 1], ['verify', '=', 1]];
        $lists   = $topicDb->where($where)->select(['id', 'title'])->get();

        return $this->success($lists);
    }

}


